package com.ch.sys.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class SHA1 {
	
	//5edaee36310bda8bd07b6328d020d6d1a644bf
	public static void main(String[] args) {
		System.out.println(SHA1.signature("1"));
	}
	
	private static final String KEY = "S1A5SA24521SFA34SDF234ASDFS3";
	

	public static String signature(String inStr) {
		MessageDigest md = null;
		String outStr = null;
		try {
			inStr = MD5.signature(inStr + KEY);
			md = MessageDigest.getInstance("SHA-1");
			byte[] digest = md.digest(inStr.getBytes());
			outStr = bytetoString(digest);
		} catch (NoSuchAlgorithmException nsae) {
			nsae.printStackTrace();
		}
		return outStr;
	}

	public static String bytetoString(byte[] digest) {
		String str = "";
		String tempStr = "";

		for (int i = 1; i < digest.length; i++) {
			tempStr = (Integer.toHexString(digest[i] & 0xff));
			if (tempStr.length() == 1) {
				str = str + "0" + tempStr;
			} else {
				str = str + tempStr;
			}
		}
		return str.toLowerCase();
	}
}
